home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample⁄Test Applications / InputSprocketPPTest / ISpElementView.cp next >
Encoding:
Text File  |  1998-07-17  |  5.4 KB  |  224 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      ISpElementView.cp
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18. #include "ISpElementView.h"
  19. #include "ISpTestGlobals.h"
  20. #include <TextUtils.h>
  21. #include "ISpPPTestTools.h"
  22.  
  23. ISpElementView::ISpElementView(LStream *inStream):LOffscreenView(inStream)
  24. {
  25.     StartIdling();
  26. }
  27.  
  28. ISpElementView::~ISpElementView()
  29. {
  30. }
  31.  
  32. ISpElementView *ISpElementView::CreateISpElementViewStream(LStream *inStream)
  33. {
  34.   return (new ISpElementView(inStream));
  35. }
  36.  
  37.  
  38. void ISpElementView::SpendTime(const EventRecord &inMacEvent)
  39. {
  40.     inMacEvent;
  41.     
  42.     Refresh();
  43.     UpdatePort();
  44. }
  45.  
  46.  
  47. void ISpElementView::DrawSelf()
  48. {
  49.     if (gElement == nil) { return; }
  50.     
  51.     Rect r;
  52.     Str255 theString;
  53.         
  54.     CalcLocalFrameRect(r);
  55.     r.left += 10;
  56.     
  57.     EraseRect(&r);
  58.     
  59.     OSStatus pollStatus;
  60.     UInt32 state = 0;
  61.     
  62.     pollStatus = ISpElement_GetSimpleState(gElement, &state);
  63.     ISpElementInfo info;
  64.     ISpElement_GetInfo(gElement, &info);
  65.     
  66.     MoveTo(r.left, r.top + 15);
  67.     DrawString("\pGlobal Error Code:  ");
  68.     NumToString(gStatus, theString);
  69.     DrawString(theString);
  70.  
  71.     MoveTo(r.left, r.top + 30);
  72.     DrawString("\pPoll Error Code:  ");
  73.     NumToString(pollStatus, theString);
  74.     DrawString(theString);
  75.  
  76.     MoveTo(r.left, r.top + 45);
  77.     DrawString("\pData:  ");
  78.     UInt32ToHexString(state, theString);
  79.     DrawString(theString);
  80.  
  81.     const rectWidth = 100;
  82.     Rect maxRect = {2,0,11,rectWidth};
  83.     Rect progRect = maxRect;
  84.     float percent;
  85.  
  86.     switch(info.theKind)
  87.     {
  88.         case kISpElementKind_Axis:
  89.         {
  90.             percent = state;
  91.             percent /= 0xffffffff;            
  92.         }
  93.         break;
  94.     
  95.         case kISpElementKind_Delta:
  96.         {
  97.             float inches = ((float) (Fixed) state) / (float) 0xffff;
  98.             
  99.             percent = 0.5 + (inches / 2);
  100.         }    
  101.     }
  102.     if (percent > 1) { percent = 1; }
  103.     if (percent < 0) { percent = 0; }
  104.     
  105.     progRect.right = rectWidth * percent;
  106.             
  107.     OffsetRect(&maxRect, r.left, r.top + 47);
  108.     OffsetRect(&progRect, r.left, r.top + 47);
  109.             
  110.     ::FrameRect(&maxRect);
  111.     ::PaintRect(&progRect);
  112.  
  113.     
  114.     MoveTo(r.left, r.top + 75);
  115.     DrawString("\pElement Num:  ");
  116.     UInt32ToHexString((unsigned long) gElement, theString);
  117.     DrawString(theString);
  118.  
  119.     MoveTo(r.left, r.top + 90);
  120.     DrawString("\pElement Label:  ");
  121.     UInt32ToFourByte(info.theLabel, theString);
  122.     DrawString(theString);
  123.  
  124.     MoveTo(r.left, r.top + 105);
  125.     DrawString("\pElement Kind:  ");
  126.     UInt32ToFourByte(info.theKind, theString);
  127.     DrawString(theString);
  128.  
  129.     MoveTo(r.left, r.top + 120);
  130.     DrawString("\pElement Name:  ");
  131.     DrawString(info.theString);
  132.  
  133.     MoveTo(r.left, r.top + 135);
  134.     ISpDeviceReference device;
  135.     ISpElement_GetDevice(gElement, &device);
  136.     ISpDeviceDefinition device_def;
  137.     ISpDevice_GetDefinition(device, sizeof(ISpDeviceDefinition), &device_def);
  138.     DrawString("\pDevice Info:  ");
  139.     DrawString(device_def.deviceName);
  140.  
  141.     DrawString("\p (");
  142.     UInt32ToFourByte(device_def.theDeviceClass, theString);
  143.     DrawString(theString);
  144.     DrawString("\p) (");
  145.     UInt32ToFourByte(device_def.theDeviceIdentifier, theString);
  146.     DrawString(theString);
  147.     DrawString("\p) (");
  148.     UInt32ToFourByte(device_def.permanentID, theString);
  149.     DrawString(theString);
  150.     DrawString("\p) (");
  151.     UInt32ToHexString(device_def.flags, theString);
  152.     DrawString(theString);
  153.     DrawString("\p)");
  154.  
  155.     MoveTo(r.left, r.top + 150);
  156.     OSStatus getConfigStatus = noErr;
  157.     switch (info.theKind)
  158.     {
  159.         case kISpElementKind_Button:
  160.             ISpButtonConfigurationInfo    buttonInfo;
  161.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (buttonInfo), &buttonInfo);
  162.             
  163.             if (getConfigStatus == noErr)
  164.             {
  165.                 DrawString("\pButton Ordering:  ");
  166.                 NumToString (buttonInfo.id, theString);
  167.                 DrawString(theString);
  168.             }
  169.             break;
  170.             
  171.         case kISpElementKind_DPad:
  172.             ISpDPadConfigurationInfo dpadInfo;
  173.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (dpadInfo), &dpadInfo);
  174.             
  175.             if (getConfigStatus == noErr)
  176.             {
  177.             DrawString("\pDPad Ordering:  ");
  178.             NumToString (dpadInfo.id, theString);
  179.             DrawString(theString);
  180.             
  181.             MoveTo(r.left, r.top + 165);
  182.             DrawString("\pIs Four-Way Pad:  ");
  183.             if (dpadInfo.fourWayPad)
  184.                 DrawString("\pTrue");
  185.             else
  186.                 DrawString("\pFalse");
  187.             }
  188.             break;
  189.             
  190.         case kISpElementKind_Axis:
  191.             ISpAxisConfigurationInfo    axisInfo;
  192.             getConfigStatus = ISpElement_GetConfigurationInfo(gElement, sizeof (axisInfo), &axisInfo);
  193.             
  194.             if (getConfigStatus == noErr)
  195.             {
  196.                 DrawString("\pAxis Is Symetric:  ");
  197.                 if (axisInfo.symetricAxis)
  198.                     DrawString("\pTrue");
  199.                 else
  200.                     DrawString("\pFalse");
  201.             }
  202.             break;
  203.         
  204.         case kISpElementKind_Delta:
  205.             DrawString("\pNo Configuration for kISpElementKind_Delta kind  ");
  206.             break;
  207.  
  208.         case kISpElementKind_Movement:
  209.             DrawString("\pNo Configuration for kISpElementKind_Movement kind  ");
  210.             break;
  211.  
  212.         case kISpElementKind_Virtual:
  213.             DrawString("\pNo Configuration for kISpElementKind_Virtual kind  ");
  214.             break;
  215.     }
  216.     
  217.     if (getConfigStatus != noErr)
  218.     {
  219.         DrawString("\pISpElement_GetConfigurationInfo error:  ");
  220.         NumToString (getConfigStatus, theString);
  221.         DrawString(theString);
  222.     }
  223.  
  224. }